#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int kind, maxWeight;
    cin >> kind >> maxWeight;

    vector<int> weight(kind + 1), value(kind + 1);
    vector<int> dp(maxWeight + 1);
    for (int i = 1; i <= kind; ++i) {
        cin >> weight[i] >> value[i];
    }

    for (int i = 1; i <= kind; ++i) {
        for (int j = weight[i]; j <= maxWeight; ++j) {
            dp[j] = max(dp[j], dp[j - weight[i]] + value[i]);
        }
    }

    cout << dp[maxWeight] << endl;
    return 0;
}
